package com.zhengshang.api.controller.shopping;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pdd.pop.sdk.common.util.JsonUtil;
import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkMemberAuthorityQueryRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkRpPromUrlGenerateRequest;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkMemberAuthorityQueryResponse;
import com.pdd.pop.sdk.http.api.pop.response.PddDdkRpPromUrlGenerateResponse;
import com.zhengshang.api.domain.AppBrowseRecord;
import com.zhengshang.api.service.IAppBrowseRecordService;
import com.zhengshang.common.annotation.RepeatSubmit;
import com.zhengshang.common.constant.app.ShoppingConstant;
import com.zhengshang.common.core.controller.BaseController;
import com.zhengshang.common.core.domain.AjaxResult;
import com.zhengshang.common.core.domain.model.LoginAppUser;
import com.zhengshang.common.utils.StringUtils;
import com.zhengshang.common.utils.http.HttpUtils;
import com.zhengshang.common.utils.sign.SignMD5Util;
import com.zhengshang.security.service.TokenService;
import com.zhengshang.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;

/**
 * 首页Controller
 *
 * @author zhengshang
 * @date 2021-03-09
 */
@Api(tags = "省钱(购物)模块")
@RestController
@RequestMapping("/shopping")
public class ShoppingController extends BaseController {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IAppBrowseRecordService appBrowseRecordService;
    @Autowired
    private ISysConfigService configService;

    /**
     * 超级分类
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "超级分类", notes = "该接口返回大淘客所有的一级分类和二级分类，且提供一级分类图标及二级分类图标素材" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=10")
    @RepeatSubmit
    @GetMapping("/superCategory")
    public AjaxResult superCategory(
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.1.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.SUPER_CATEGORY_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

//    /**
//     * 细分类目合集
//     */
//    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
//    @ApiOperation(value = "细分类目合集", notes = "该接口返回大淘客所有的细分类目合集（如手机，螺蛳粉、电吹风）" +
//            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=68")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "cid", value = "大淘客一级分类ID，1 -女装，2 -母婴，3 -美妆，4 -居家日用，5 -鞋品，6 -美食，7 -文娱车品，8 -数码家电，9 -男装，10 -内衣，11 -箱包，12 -配饰，13 -户外运动，14 -家装家纺", required = true, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "pageId", value = "分页id：常规分页方式，请直接传入对应页码（比如：1,2,3……）", required = true, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "pageSize", value = "每页条数，默认20，最大100条", dataType = "int", required = true, paramType = "query")
//    })
//    @RepeatSubmit
//    @GetMapping("/subdivisionList")
//    public AjaxResult subdivisionList(
//            @RequestParam Integer cid,
//            @RequestParam Integer pageId,
//            @RequestParam Integer pageSize,
//            HttpServletRequest request, HttpServletResponse response)
//    {
//        if (cid == null || pageId == null || pageSize == null) {
//            return AjaxResult.error("参数错误");
//        }
//        if (pageSize > 100) {
//            return AjaxResult.error("每页最多显示100条数据");
//        }
//        final String version = "v1.0.0";//接口版本号
//        TreeMap<String, String> paramMap = new TreeMap<>();
//        paramMap.put("appKey", ShoppingConstant.APP_KEY);
//        paramMap.put("version", version);
//        paramMap.put("cid", cid + "");
//        paramMap.put("pageId", pageId + "");
//        paramMap.put("pageSize", pageSize + "");
//        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
//
//        String reslutStr = HttpUtils.sendGet(ShoppingConstant.SUBDIVISION_LIST_URL, paramMap);
//        return convertDataokeData(reslutStr);
//    }

//    /**
//     * 细分类目榜（淘宝、天猫）
//     */
//    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
//    @ApiOperation(value = "细分类目榜（淘宝、天猫）", notes = "该接口返回某个具体细分类目榜单前20名商品数据。" +
//            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=41")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "subdivisionId", value = "细分类目榜分类id（从商品详情获取）", required = true, dataType = "String", paramType = "query")
//    })
//    @RepeatSubmit
//    @GetMapping("/subdivisionRankList")
//    public AjaxResult subdivisionRankList(
//            @RequestParam String subdivisionId,
//            HttpServletRequest request, HttpServletResponse response)
//    {
//        if (StringUtils.isBlank(subdivisionId)) {
//            return AjaxResult.error("参数错误");
//        }
//        final String version = "v1.0.0";//接口版本号
//        TreeMap<String, String> paramMap = new TreeMap<>();
//        paramMap.put("appKey", ShoppingConstant.APP_KEY);
//        paramMap.put("version", version);
//        paramMap.put("subdivisionId", subdivisionId);
//        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
//
//        String reslutStr = HttpUtils.sendGet(ShoppingConstant.SUBDIVISION_RANK_LIST_URL, paramMap);
//        return convertDataokeData(reslutStr);
//    }

//    /**
//     * 各大榜单（淘宝、天猫）
//     */
//    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
//    @ApiOperation(value = "各大榜单（淘宝、天猫）", notes = "该接口返回的是大淘客平台实时榜、热推榜、全天销量榜、复购榜的前200条商品数据" +
//            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=6")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "rankType", value = "榜单类型，1.实时榜 2.全天榜 3.热推榜 4.复购榜 5.热词飙升榜 6.热词排行榜 7.综合热搜榜", required = true, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "cid", value = "大淘客一级类目id，仅对实时榜单、全天榜单有效", required = false, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "pageSize", value = "每页条数返回条数（支持10,20,50，默认返回20条）", required = false, dataType = "int", paramType = "query"),
//            @ApiImplicitParam(name = "pageId", value = "分页id：常规分页方式，请直接传入对应页码（比如：1,2,3……）。超过200条，分页返回为空", required = false, dataType = "String", paramType = "query")
//    })
//    @RepeatSubmit
//    @GetMapping("/goodsRankingList")
//    public AjaxResult goodsRankingList(
//            @RequestParam Integer rankType,
//            @RequestParam(required = false) Integer cid,
//            @RequestParam(required = false) Integer pageSize,
//            @RequestParam(required = false) String pageId,
//            HttpServletRequest request, HttpServletResponse response)
//    {
//        if (rankType == null) {
//            return AjaxResult.error("参数错误");
//        }
//        final String version = "v1.3.0";//接口版本号
//        TreeMap<String, String> paramMap = new TreeMap<>();
//        paramMap.put("appKey", ShoppingConstant.APP_KEY);
//        paramMap.put("version", version);
//        paramMap.put("rankType", rankType + "");
//        paramMap.put("cid", cid + "");
//        paramMap.put("pageSize", pageSize + "");
//        paramMap.put("pageId", pageId);
//        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
//
//        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_RANKING_LIST_URL, paramMap);
//        return convertDataokeData(reslutStr);
//    }

    /**
     * 商品列表
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "商品列表", notes = "该接口返回筛选条件内的所有商品列表和商品信息" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=5")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageId", value = "默认为1，支持传统的页码分页方式和scroll_id分页方式，根据用户自身需求传入值。示例1：商品入库，则首次传入1，后续传入接口返回的pageid，接口将持续返回符合条件的完整商品列表，该方式可以避免入口商品重复；示例2：根据pagesize和totalNum计算出总页数，按照需求返回指定页的商品（该方式可能在临近页取到重复商品）", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数，默认为100，最大值200，若小于10，则按10条处理，每页条数仅支持输入10,50,100,200", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序方式，默认为0，0-综合排序，1-商品上架时间从高到低，2-销量从高到低，3-领券量从高到低，4-佣金比例从高到低，5-价格（券后价）从高到低，6-价格（券后价）从低到高", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "cids", value = "大淘客的一级分类id，如果需要传多个，以英文逗号相隔，如：”1,2,3”。当一级类目id和二级类目id同时传入时，会自动忽略二级类目id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "subcid", value = "大淘客的二级类目id，通过超级分类API获取。仅允许传一个二级id，当一级类目id和二级类目id同时传入时，会自动忽略二级类目id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "specialId", value = "商品卖点，1.拍多件活动；2.多买多送；3.限量抢购；4.额外满减；6.买商品礼赠", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "juHuaSuan", value = "1-聚划算商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "taoQiangGou", value = "1-淘抢购商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "tmall", value = "1-天猫商品， 0-非天猫商品，不填默认所有商品", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "tchaoshi", value = "1-天猫超市商品， 0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "goldSeller", value = "1-金牌卖家商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "haitao", value = "1-海淘商品， 0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pre", value = "1-预告商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "preSale", value = "1-活动预售商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "brand", value = "1-品牌商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "brandIds", value = "当brand传入0时，再传入brandIds可能无法获取结果。品牌id可以传多个，以英文逗号隔开，如：”345,321,323”", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "priceLowerLimit", value = "价格（券后价）下限", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "priceUpperLimit", value = "价格（券后价）上限", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "couponPriceLowerLimit", value = "最低优惠券面额", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "commissionRateLowerLimit", value = "最低佣金比率", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "monthSalesLowerLimit", value = "最低月销量", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "freeshipRemoteDistrict", value = "偏远地区包邮，1-是，0-非偏远地区，不填默认所有商品", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "directCommissionType", value = "定向佣金类型，3查询定向佣金商品，否则查询全部商品（12.22新增字段）", required = false, dataType = "int", paramType = "query")
    })
    @GetMapping("/goodsList")
    public AjaxResult goodsList(
            @RequestParam String pageId,
            @RequestParam(required = false, defaultValue = "20") Integer pageSize,
            @RequestParam(required = false) String sort,
            @RequestParam(required = false) String cids,
            @RequestParam(required = false) Integer subcid,
            @RequestParam(required = false) Integer specialId,
            @RequestParam(required = false) Integer juHuaSuan,
            @RequestParam(required = false) Integer taoQiangGou,
            @RequestParam(required = false) Integer tmall,
            @RequestParam(required = false) Integer tchaoshi,
            @RequestParam(required = false) Integer goldSeller,
            @RequestParam(required = false) Integer haitao,
            @RequestParam(required = false) Integer pre,
            @RequestParam(required = false) Integer preSale,
            @RequestParam(required = false) Integer brand,
            @RequestParam(required = false) Integer brandIds,
            @RequestParam(required = false) Integer priceLowerLimit,
            @RequestParam(required = false) Integer priceUpperLimit,
            @RequestParam(required = false) Integer couponPriceLowerLimit,
            @RequestParam(required = false) Integer commissionRateLowerLimit,
            @RequestParam(required = false) Integer monthSalesLowerLimit,
            @RequestParam(required = false) Integer freeshipRemoteDistrict,
            @RequestParam(required = false) Integer directCommissionType,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(pageId)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.2.4";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("pageId", pageId);
        paramMap.put("pageSize", pageSize == null ? "" : pageSize + "");

        if (StringUtils.isNotBlank(sort)) {
            paramMap.put("sort", sort);
        }
        if (StringUtils.isNotBlank(cids)) {
            paramMap.put("cids", cids);
        }
        if (subcid != null) {
            paramMap.put("subcid", subcid + "");
        }
        if (specialId != null) {
            paramMap.put("specialId", specialId + "");
        }
        if (juHuaSuan != null) {
            paramMap.put("juHuaSuan", juHuaSuan + "");
        }
        if (taoQiangGou != null) {
            paramMap.put("taoQiangGou", taoQiangGou + "");
        }
        if (tmall != null) {
            paramMap.put("tmall", tmall + "");
        }
        if (tchaoshi != null) {
            paramMap.put("tchaoshi", tchaoshi + "");
        }
        if (goldSeller != null) {
            paramMap.put("goldSeller", goldSeller + "");
        }
        if (haitao != null) {
            paramMap.put("haitao", haitao + "");
        }
        if (pre != null) {
            paramMap.put("pre", pre + "");
        }
        if (preSale != null) {
            paramMap.put("preSale", preSale + "");
        }
        if (brand != null) {
            paramMap.put("brand", brand + "");
        }
        if (brandIds != null) {
            paramMap.put("brandIds", brandIds + "");
        }
        if (priceLowerLimit != null) {
            paramMap.put("priceLowerLimit", priceLowerLimit + "");
        }
        if (priceUpperLimit != null) {
            paramMap.put("priceUpperLimit", priceUpperLimit + "");
        }
        if (couponPriceLowerLimit != null) {
            paramMap.put("couponPriceLowerLimit", couponPriceLowerLimit + "");
        }
        if (commissionRateLowerLimit != null) {
            paramMap.put("commissionRateLowerLimit", commissionRateLowerLimit + "");
        }
        if (monthSalesLowerLimit != null) {
            paramMap.put("monthSalesLowerLimit", monthSalesLowerLimit + "");
        }
        if (freeshipRemoteDistrict != null) {
            paramMap.put("freeshipRemoteDistrict", freeshipRemoteDistrict + "");
        }
        if (directCommissionType != null) {
            paramMap.put("directCommissionType", directCommissionType + "");
        }
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_LIST_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 单品详情
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "单品详情（淘宝、天猫）", notes = "通过大淘客商品id或淘宝商品id查询商品详细信息" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=8")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "大淘客商品id，请求时id或goodsId必填其中一个，若均填写，将优先查找当前单品id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "goodsId", value = "淘宝商品id，id或goodsId必填其中一个，若均填写，将优先查找当前单品id", required = false, dataType = "String", paramType = "query")
    })
    @RepeatSubmit
    @GetMapping("/goodsDetails")
    public AjaxResult goodsDetails(
            @RequestParam Integer id,
            @RequestParam(required = false) String goodsId,
            HttpServletRequest request, HttpServletResponse response) {
        if (id == null) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.2.3";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);
        paramMap.put("id", id + "");
        paramMap.put("goodsId", goodsId);
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        //浏览记录
        LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);
        AppBrowseRecord appBrowseRecord = new AppBrowseRecord();
        appBrowseRecord.setRecordType("1");
        appBrowseRecord.setRecordSource("1");
        appBrowseRecord.setUserId(loginAppUser.getAppUser().getUserId());
        appBrowseRecord.setInfoId(id + "");
        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_DETAILS_URL, paramMap);
        AjaxResult ajaxResult = convertDataokeData(reslutStr, appBrowseRecord);

        appBrowseRecordService.insertAppBrowseRecord(appBrowseRecord);
        return ajaxResult;
    }

    /**
     * 京东商品详情
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "京东商品详情", notes = "通过京东商品skuId查看商品详细信息，最多支持10个商品同时查询" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=64")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuIds", value = "商品skuId，多个使用逗号分隔，最多支持10个skuId同时查询（需使用半角状态下的逗号）", required = true, dataType = "String", paramType = "query")
    })
    @RepeatSubmit
    @GetMapping("/goodsDetailsJD")
    public AjaxResult goodsDetailsJD(
            @RequestParam String skuIds,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(skuIds) || skuIds.split(",").length > 10) {
            return AjaxResult.error("参数不正确！");
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);
        paramMap.put("skuIds", skuIds);
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        //浏览记录
        AppBrowseRecord appBrowseRecord = new AppBrowseRecord();
        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_DETAILS_JD_URL, paramMap);
        AjaxResult ajaxResult = convertDataokeData(reslutStr, appBrowseRecord);

        LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);
        appBrowseRecord.setRecordType("1");
        appBrowseRecord.setRecordSource("2");
        appBrowseRecord.setUserId(loginAppUser.getAppUser().getUserId());
        appBrowseRecord.setInfoId(skuIds);
        appBrowseRecordService.insertAppBrowseRecord(appBrowseRecord);
        return ajaxResult;
    }

    /**
     * 超级搜索（淘宝、天猫搜索）
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "超级搜索（淘宝、天猫搜索）", notes = "该接口通过关键词搜索以及其他筛选条件返回京东联盟对应条件的商品数据" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=70")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "搜索类型：0-综合结果，1-大淘客商品，2-联盟商品", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageId", value = "请求的页码，默认参数1", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数，默认为20，最大值100", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "keyWords", value = "关键词搜索", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tmall", value = "是否天猫商品：1-天猫商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "haitao", value = "是否海淘商品：1-海淘商品，0-所有商品，不填默认为0", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序字段信息 销量（total_sales） 价格（price），排序_des（降序），排序_asc（升序），示例：升序查询销量total_sales_asc 新增排序字段和排序方式，默认为0，0-综合排序，1-销量从高到低，2-销量从低到高，3-佣金比例从低到高，4-佣金比例从高到低，5-价格从高到低，6-价格从低到高(2021/1/15新增字段，之前的排序方式也可以使用)", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "specialId", value = "会员运营id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "channelId", value = "渠道id将会和传入的pid进行验证，验证通过将正常转链，请确认填入的渠道id是正确的channelId对应联盟的relationId", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "priceLowerLimit", value = "商品券后价下限", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "priceUpperLimit", value = "商品券后价上限", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "startTkRate", value = "淘客佣金比率下限", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "endTkRate", value = "淘客佣金比率上限", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "hasCoupon", value = "是否有券，1为有券，默认为全部", required = false, dataType = "String", paramType = "query"),
    })
    @GetMapping("/goodsSearchSuper")
    public AjaxResult goodsSearchSuper(
            @RequestParam Integer type,
            @RequestParam Integer pageId,
            @RequestParam Integer pageSize,
            @RequestParam String keyWords,
            @RequestParam(required = false) Integer tmall,
            @RequestParam(required = false) Integer haitao,
            @RequestParam(required = false) Integer sort,
            @RequestParam(required = false) String specialId,
            @RequestParam(required = false) String channelId,
            @RequestParam(required = false) String priceLowerLimit,
            @RequestParam(required = false) String priceUpperLimit,
            @RequestParam(required = false) String startTkRate,
            @RequestParam(required = false) String endTkRate,
            @RequestParam(required = false) String hasCoupon,
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        if (type != null) paramMap.put("type", type + "");
        if (pageId != null) paramMap.put("pageId", pageId + "");
        if (pageSize != null) paramMap.put("pageSize", pageSize + "");
        if (StringUtils.isNotBlank(keyWords)) paramMap.put("keyWords", keyWords);
        if (tmall != null) paramMap.put("tmall", tmall + "");
        if (haitao != null) paramMap.put("haitao", haitao + "");
        if (sort != null) paramMap.put("sort", sort + "");
        if (StringUtils.isNotBlank(specialId)) paramMap.put("specialId", specialId);
        if (StringUtils.isNotBlank(channelId)) paramMap.put("channelId", channelId);
        if (StringUtils.isNotBlank(priceLowerLimit)) paramMap.put("priceLowerLimit", priceLowerLimit);
        if (StringUtils.isNotBlank(priceUpperLimit)) paramMap.put("priceUpperLimit", priceUpperLimit);
        if (StringUtils.isNotBlank(startTkRate)) paramMap.put("startTkRate", startTkRate);
        if (StringUtils.isNotBlank(endTkRate)) paramMap.put("endTkRate", endTkRate);
        if (StringUtils.isNotBlank(hasCoupon)) paramMap.put("hasCoupon", hasCoupon);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_SEARCH_SUPER_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 京东联盟搜索（搜索）
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "京东联盟搜索（搜索）", notes = "该接口通过关键词搜索以及其他筛选条件返回京东联盟对应条件的商品数据" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=70")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cid1", value = "一级类目id", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "cid2", value = "二级类目id", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "cid3", value = "三级类目id", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "pageId", value = "页码", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量，单页数最大30，默认20", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "skuIds", value = "skuid集合(一次最多支持查询100个sku)，多个使用“,”分隔符", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键词，字数同京东商品名称一致，目前未限制", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "priceFrom", value = "商品券后价格下限", required = false, dataType = "bigDecimal", paramType = "query"),
            @ApiImplicitParam(name = "priceTo", value = "商品券后价格上限", required = false, dataType = "bigDecimal", paramType = "query"),
            @ApiImplicitParam(name = "commissionShareStart", value = "佣金比例区间开始", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "commissionShareEnd", value = "佣金比例区间结束", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "owner", value = "商品类型：自营[g]，POP[p]", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sortName", value = "排序字段(price：单价, commissionShare：佣金比例, commission：佣金， inOrderCount30Days：30天引单量， inOrderComm30Days：30天支出佣金)", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "asc：升序；desc：降序。默认降序", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isCoupon", value = "是否是优惠券商品，1：有优惠券，0：无优惠券", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pingouPriceStart", value = "拼购价格区间开始", required = false, dataType = "bigDecimal", paramType = "query"),
            @ApiImplicitParam(name = "pingouPriceEnd", value = "拼购价格区间结束", required = false, dataType = "bigDecimal", paramType = "query"),
            @ApiImplicitParam(name = "brandCode", value = "品牌code", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "shopId", value = "店铺Id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "hasBestCoupon", value = "1：查询有最优惠券商品；其他值过滤掉此入参条件。（查询最优券需与isCoupon同时使用）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pid", value = "联盟id_应用iD_推广位id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "jxFlags", value = "京喜商品类型，1京喜、2京喜工厂直供、3京喜优选（包含3时可在京东APP购买），入参多个值表示或条件查询", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "spuId", value = "主商品spuId", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "couponUrl", value = "优惠券链接", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deliveryType", value = "京东配送 1：是，0：不是", required = false, dataType = "int", paramType = "query"),
    })
    @GetMapping("/goodsSearchJD")
    public AjaxResult goodsSearchJD(
            @RequestParam(required = false) Long cid1,
            @RequestParam(required = false) Long cid2,
            @RequestParam(required = false) Long cid3,
            @RequestParam(required = false) Integer pageId,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String skuIds,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) BigDecimal priceFrom,
            @RequestParam(required = false) BigDecimal priceTo,
            @RequestParam(required = false) Integer commissionShareStart,
            @RequestParam(required = false) Integer commissionShareEnd,
            @RequestParam(required = false) String owner,
            @RequestParam(required = false) String sortName,
            @RequestParam(required = false) String sort,
            @RequestParam(required = false) String isCoupon,
            @RequestParam(required = false) BigDecimal pingouPriceStart,
            @RequestParam(required = false) BigDecimal pingouPriceEnd,
            @RequestParam(required = false) String brandCode,
            @RequestParam(required = false) Integer shopId,
            @RequestParam(required = false) Integer hasBestCoupon,
            @RequestParam(required = false) String pid,
            @RequestParam(required = false) String jxFlags,
            @RequestParam(required = false) Long spuId,
            @RequestParam(required = false) String couponUrl,
            @RequestParam(required = false) Integer deliveryType,
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        if (cid1 != null) paramMap.put("cid1", cid1 + "");
        if (cid2 != null) paramMap.put("cid2", cid2 + "");
        if (cid3 != null) paramMap.put("cid3", cid3 + "");
        if (pageId != null) paramMap.put("pageId", pageId + "");
        if (pageSize != null) paramMap.put("pageSize", pageSize + "");
        if (StringUtils.isNotBlank(skuIds)) paramMap.put("skuIds", skuIds + "");
        if (StringUtils.isNotBlank(keyword)) paramMap.put("keyword", keyword + "");
        if (priceFrom != null) paramMap.put("priceFrom", priceFrom + "");
        if (priceTo != null) paramMap.put("priceTo", priceTo + "");
        if (commissionShareStart != null) paramMap.put("commissionShareStart", commissionShareStart + "");
        if (commissionShareEnd != null) paramMap.put("commissionShareEnd", commissionShareEnd + "");
        if (StringUtils.isNotBlank(owner)) paramMap.put("owner", owner + "");
        if (StringUtils.isNotBlank(sortName)) paramMap.put("sortName", sortName + "");
        if (StringUtils.isNotBlank(sort)) paramMap.put("sort", sort + "");
        if (StringUtils.isNotBlank(isCoupon)) paramMap.put("isCoupon", isCoupon + "");
        if (pingouPriceStart != null) paramMap.put("pingouPriceStart", pingouPriceStart + "");
        if (pingouPriceEnd != null) paramMap.put("pingouPriceEnd", pingouPriceEnd + "");
        if (StringUtils.isNotBlank(brandCode)) paramMap.put("brandCode", brandCode + "");
        if (shopId != null) paramMap.put("shopId", shopId + "");
        if (hasBestCoupon != null) paramMap.put("hasBestCoupon", hasBestCoupon + "");
        if (StringUtils.isNotBlank(pid)) paramMap.put("pid", pid + "");
        if (StringUtils.isNotBlank(jxFlags)) paramMap.put("jxFlags", jxFlags + "");
        if (spuId != null) paramMap.put("spuId", spuId + "");
        if (StringUtils.isNotBlank(couponUrl)) paramMap.put("couponUrl", couponUrl + "");
        if (deliveryType != null) paramMap.put("deliveryType", deliveryType + "");

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_SEARCH_JD_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 拼多多联盟搜索（搜索）
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "拼多多联盟搜索（搜索）", notes = "该接口通过关键词搜索以及其他筛选条件返回拼多多联盟对应条件商品" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=71")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "activityTags,", value = "活动商品标记数组，例：[4,7]， 4-秒杀，7-百亿补贴，31-品牌黑标，10564-精选爆品-官方直推爆款，10584-精选爆品-团长推荐， 24-品牌高佣，20-行业精选，21-金牌商家，10044-潜力爆品，10475-爆品上新，其他的值请忽略", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "blockCats,", value = "自定义屏蔽一级/二级/三级类目ID，自定义数量不超过20个;", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "blockCatPackages,", value = "屏蔽商品类目包：1-拼多多小程序屏蔽的类目&关键词;2-虚拟类目;3-医疗器械;4-处方药;5-非处方药", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "catId,", value = "商品类目ID", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "goodsSignList,", value = "商品goodsSign列表", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isBrandGoods,", value = "是否为品牌商品", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "keyword,", value = "商品关键词", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "listId,", value = "翻页时建议填写前页返回的list_id值", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "merchantType,", value = "店铺类型，1-个人，2-企业，3-旗舰店，4-专卖店，5-专营店，6-普通店（未传为全部）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "merchantTypeList,", value = "店铺类型数组", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "optId,", value = "商品标签类目ID", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "page,", value = "默认值1，商品分页数", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize,", value = "默认100，每页商品数量", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "rangeList,", value = "筛选范围列表 样例：[{\"range_id\":0,\"range_from\":1,\"range_to\":1500}, {\"range_id\":1,\"range_from\":1,\"range_to\":1500}]", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sortType,", value = "排序方式:0-综合排序;1-按佣金比率升序;2-按佣金比例降序;3-按价格升序;4-按价格降序;5-按销量升序; 6-按销量降序;7-优惠券金额排序升序;8-优惠券金额排序降序; 9-券后价升序排序;10-券后价降序排序;11-按照加入多多进宝时间升序;12-按照加入多多进宝时间降序; 13-按佣金金额升序排序;14-按佣金金额降序排序;15-店铺描述评分升序; 16-店铺描述评分降序;17-店铺物流评分升序;18-店铺物流评分降序;19-店铺服务评分升序;20-店铺服务评分降序; 27-描述评分击败同类店铺百分比升序，28-描述评分击败同类店铺百分比降序， 29-物流评分击败同类店铺百分比升序，30-物流评分击败同类店铺百分比降序，31-服务评分击败同类店铺百分比升序， 32-服务评分击败同类店铺百分比降序", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "withCoupon,", value = "是否只返回优惠券的商品，false返回所有商品，true只返回有优惠券的商品", required = false, dataType = "int", paramType = "query"),
    })
    @GetMapping("/goodsSearchPDD")
    public AjaxResult goodsSearchPDD(
            @RequestParam(required = false) String activityTags,
            @RequestParam(required = false) String blockCats,
            @RequestParam(required = false) String blockCatPackages,
            @RequestParam(required = false) Integer catId,
            @RequestParam(required = false) String goodsSignList,
            @RequestParam(required = false) Integer isBrandGoods,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) String listId,
            @RequestParam(required = false) Integer merchantType,
            @RequestParam(required = false) String merchantTypeList,
            @RequestParam(required = false) Integer optId,
            @RequestParam(required = false) Integer page,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String rangeList,
            @RequestParam(required = false) Integer sortType,
            @RequestParam(required = false) Integer withCoupon,
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        if (StringUtils.isNotBlank(activityTags)) paramMap.put("activityTags", activityTags);
        if (StringUtils.isNotBlank(blockCats)) paramMap.put("blockCats", blockCats);
        if (StringUtils.isNotBlank(blockCatPackages)) paramMap.put("blockCatPackages", blockCatPackages);
        if (catId != null) paramMap.put("catId", catId + "");
        if (StringUtils.isNotBlank(goodsSignList)) paramMap.put("goodsSignList", goodsSignList);
        if (isBrandGoods != null) paramMap.put("isBrandGoods", isBrandGoods + "");
        if (StringUtils.isNotBlank(keyword)) paramMap.put("keyword", keyword);
        if (StringUtils.isNotBlank(listId)) paramMap.put("listId", listId);
        if (merchantType != null) paramMap.put("merchantType", merchantType + "");
        if (StringUtils.isNotBlank(merchantTypeList)) paramMap.put("merchantTypeList", merchantTypeList);
        if (optId != null) paramMap.put("optId", optId + "");
        if (page != null) paramMap.put("page", page + "");
        if (pageSize != null) paramMap.put("pageSize", pageSize + "");
        if (StringUtils.isNotBlank(rangeList)) paramMap.put("rangeList", rangeList + "");
        if (sortType != null) paramMap.put("sortType", sortType + "");
        if (withCoupon != null) paramMap.put("withCoupon", withCoupon + "");

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_SEARCH_PDD_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 每日爆品推荐
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "爆款推荐", notes = "该接口返回每天满足联盟爆品规则的商品合集，单价10~20元商品当日销量超过3000单，20~40元商品当日销量超过1000单，大于等于40元的销量超过500单。 （因为统计的是商品当天的销量，所以早上可能存在数量很少的情况。10分钟会刷新一次）" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=34")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageId", value = "分页id：常规分页方式，请直接传入对应页码（比如：1,2,3……）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页返回条数，每页条数支持输入10,20，50,100。默认5条", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "PriceCid", value = "价格区间，1表示10~20元区；2表示20~40元区；3表示40元以上区；默认为1", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "cids", value = "大淘客的一级分类id，如果需要传多个，以英文逗号相隔，如：”1,2,3”。1 -女装，2 -母婴，3 -美妆，4 -居家日用，5 -鞋品，6 -美食，7 -文娱车品，8 -数码家电，9 -男装，10 -内衣，11 -箱包，12 -配饰，13 -户外运动，14 -家装家纺。不填默认全部", required = false, dataType = "int", paramType = "query"),
    })
    @GetMapping("/explosiveGoodsList")
    public AjaxResult explosiveGoodsList(
            @RequestParam(required = false) Integer pageId,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String PriceCid,
            @RequestParam(required = false) String cids,
            HttpServletRequest request, HttpServletResponse response) {
        if (pageId == null) {
            pageId = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("pageId", pageId + "");
        paramMap.put("pageSize", pageSize + "");
        if (cids != null) paramMap.put("cids", cids);
        if (StringUtils.isNotBlank(PriceCid)) paramMap.put("PriceCid", PriceCid);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.EXPLOSIVE_GOODS_LIST_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 高佣精选
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "精选商品列表", notes = "该接口返回大淘客高佣商品合集，高佣金高收益（佣金比例大于等于40%）" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=59")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageId", value = "分页id：常规分页方式，请直接传入对应页码（比如：1,2,3……）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页返回条数，每页条数支持输入10,20，50,100", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cid", value = "大淘客的一级分类id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序：默认按佣金比例降序1-按销量降序，2-按销量升序，3-按佣金比例降序，4-按佣金比例升序。", required = false, dataType = "int", paramType = "query"),
    })
    @GetMapping("/heigntCommissionList")
    public AjaxResult heigntCommissionList(
            @RequestParam(required = false) Integer pageId,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) Integer cid,
            @RequestParam(required = false) Integer sort,
            HttpServletRequest request, HttpServletResponse response) {
        if (pageId == null) {
            pageId = 1;
        }
        if (pageSize == null) {
            pageSize = 6;
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("pageId", pageId + "");
        paramMap.put("pageSize", pageSize + "");
        if (cid != null) paramMap.put("cid", cid + "");
        if (sort != null) paramMap.put("sort", sort + "");

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.HEIGHT_COMMISSION_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 热搜榜
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "热搜榜", notes = "该接口返回近期热搜话题相关商品的合集" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=61")
    @GetMapping("/hotWordsList")
    public AjaxResult hotWordsList(
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.HOT_WORDS_LIST_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 热搜记录
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "热搜记录", notes = "该接口返回昨日大淘客CMS端采集统计的前100名搜索热词" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=4")
    @RepeatSubmit
    @GetMapping("/getCategoryTop100List")
    public AjaxResult getCategoryTop100List(
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v1.0.1";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GET_CATEGORY_TOP100_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 联想词
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "联想词", notes = "该接口返回关键词的关联词汇，建议用户停止输入时调用接口返回联想词" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=18")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyWords", value = "关键词", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "当前搜索API类型：1.大淘客搜索 2.联盟搜索 3.超级搜索", required = true, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/searchSuggestionList")
    public AjaxResult searchSuggestionList(
            @RequestParam String keyWords,
            @RequestParam String type,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(keyWords) || StringUtils.isBlank(type)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.0.2";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("keyWords", keyWords);
        paramMap.put("type", type);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.SEARCH_SUGGESTION_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 轮播图
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "轮播图", notes = "由大淘客数据+人工甄选的优质商品，以专题的方式开放给开发者，专题商品优质高转化" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=72")
    @RepeatSubmit
    @GetMapping("/carouseList")
    public AjaxResult carouseList(
            HttpServletRequest request, HttpServletResponse response) {
        final String version = "v2.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.CAROUSE_LIST_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 收藏商品
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "收藏商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "淘宝：大淘客商品id，京东：商品skuId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "source", value = "所属平台（1淘宝天猫，2京东）", required = true, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @PostMapping("/collectionGoods")
    public AjaxResult collectionGoods(
            @RequestParam String id,
            @RequestParam String source,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(id) || StringUtils.isBlank(source)) {
            return AjaxResult.error("参数错误");
        }
        try {
            LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);
            AppBrowseRecord appBrowseRecord = new AppBrowseRecord();
            appBrowseRecord.setRecordType("2");
            appBrowseRecord.setUserId(loginAppUser.getAppUser().getUserId());
            appBrowseRecord.setInfoId(id);
            appBrowseRecord.setRecordSource(source);
            if (appBrowseRecordService.selectAppBrowseRecordList(appBrowseRecord).size() > 0) {
                return AjaxResult.error("该商品已收藏过");
            }

            if ("1".equals(source)) {

                final String version = "v1.2.3";//接口版本号
                TreeMap<String, String> paramMap = new TreeMap<>();
                paramMap.put("appKey", ShoppingConstant.APP_KEY);
                paramMap.put("version", version);
                paramMap.put("id", id);
                paramMap.put("goodsId", null);
                paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
                String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_DETAILS_URL, paramMap);
                convertDataokeData(reslutStr, appBrowseRecord);
            } else if ("2".equals(source)) {

                final String version = "v1.0.0";//接口版本号
                TreeMap<String, String> paramMap = new TreeMap<>();
                paramMap.put("appKey", ShoppingConstant.APP_KEY);
                paramMap.put("version", version);
                paramMap.put("skuIds", id);
                paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
                String reslutStr = HttpUtils.sendGet(ShoppingConstant.GOODS_DETAILS_JD_URL, paramMap);
                convertDataokeData(reslutStr, appBrowseRecord);
            } else {
                return AjaxResult.error("参数错误");
            }
            int row = appBrowseRecordService.insertAppBrowseRecord(appBrowseRecord);
            return AjaxResult.success(row <= 0 ? -1 : appBrowseRecord.getRecordId());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error("收藏失败，请稍后再试！");
    }

    /**
     * 查询商品是否收藏过
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "查询商品是否收藏过")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "淘宝：大淘客商品id，京东：商品skuId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "source", value = "所属平台（1淘宝天猫，2京东）", required = true, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/isCollection")
    public AjaxResult isCollection(
            @RequestParam String id,
            @RequestParam String source,
            HttpServletRequest request, HttpServletResponse response
    ) {
        try {
            LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);
            AppBrowseRecord appBrowseRecord = new AppBrowseRecord();
            appBrowseRecord.setRecordType("2");
            appBrowseRecord.setUserId(loginAppUser.getAppUser().getUserId());
            appBrowseRecord.setInfoId(id);
            appBrowseRecord.setRecordSource(source);

            List<AppBrowseRecord> appBrowseRecordList = appBrowseRecordService.selectAppBrowseRecordList(appBrowseRecord);
            return AjaxResult.success(appBrowseRecordList.size() == 0 ? -1 : appBrowseRecordList.get(0).getRecordId());
        } catch (Exception e) {
            return AjaxResult.error("查询失败", -1);
        }
    }

    /**
     * 优惠券查询
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "优惠券查询", notes = "该接口可用于获取某个具体的优惠券信息（领券量，剩余量、使用周期等等）" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=60")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "二合一链接，淘口令，或同时输入商品+优惠券链接", required = true, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/getCouponInfo")
    public AjaxResult getCouponInfo(
            @RequestParam String content,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(content)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);
        paramMap.put("content", content);
        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.GET_COUPON_INFO, paramMap);
        return convertDataokeData(reslutStr);
    }


    /**
     * 高效转链
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "高效转链", notes = "高效转链接口将您的pid信息、商品地址及优惠券信息进行转链，转链后的结果可进行推广或完成订单，接口支持授权淘宝账号下所有PID进行转链。由于接口特殊性，请适量缓存已转链的链接，以达最佳效率。" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=7")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "淘宝商品id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "couponId", value = "商品的优惠券ID，一个商品在联盟可能有多个优惠券，可通过填写该参数的方式选择使用的优惠券，请确认优惠券ID正确，否则无法正常跳转", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "channelId", value = "渠道id将会和传入的pid进行验证，验证通过将正常转链，请确认填入的渠道id是正确的 channelId对应联盟的relationId", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "rebateType", value = "付定返红包，0.不使用付定返红包，1.参与付定返红包", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "specialId", value = "会员运营id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "externalId", value = "淘宝客外部用户标记，如自身系统账户ID；微信ID等", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "xid", value = "团长与下游渠道合作的特殊标识，用于统计渠道推广效果", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "leftSymbol", value = "淘口令左边自定义符号,默认￥", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "rightSymbol", value = "淘口令右边自定义符号,默认￥", required = false, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/privilegeLink")
    public AjaxResult privilegeLink(
            @RequestParam String goodsId,
            @RequestParam(required = false) String couponId,
            @RequestParam(required = false) String channelId,
            @RequestParam(required = false) Integer rebateType,
            @RequestParam(required = false) String specialId,
            @RequestParam(required = false) String externalId,
            @RequestParam(required = false) String xid,
            @RequestParam(required = false) String leftSymbol,
            @RequestParam(required = false) String rightSymbol,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(goodsId)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.3.1";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("goodsId", StringUtils.isEmpty(goodsId) ? "" : goodsId);
        if (StringUtils.isNotBlank(couponId)) paramMap.put("couponId", couponId + "");
        if (StringUtils.isNotBlank(channelId)) paramMap.put("channelId", channelId);
        if (rebateType != null) paramMap.put("rebateType", rebateType + "");
        if (StringUtils.isNotBlank(specialId)) paramMap.put("specialId", specialId);
        if (StringUtils.isNotBlank(externalId)) paramMap.put("externalId", externalId);
        if (StringUtils.isNotBlank(xid)) paramMap.put("xid", xid);
        if (StringUtils.isNotBlank(leftSymbol)) paramMap.put("leftSymbol", leftSymbol);
        if (StringUtils.isNotBlank(rightSymbol)) paramMap.put("rightSymbol", rightSymbol);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.PRIVILEGE_LINK_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 京东商品转链
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "京东商品转链", notes = "该接口针对京东商品进行转链，转链后即可进行推广并赚取佣金" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=52")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "unionId", value = "推客的联盟ID", required = true, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "materialId", value = "推广物料url，例如活动链接、商品链接等；不支持仅传入skuid", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "positionId", value = "新增推广位id （不填的话，默认生成一个唯一此接口推广位-名称：微信手Q短链接", required = false, dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "childPid", value = "联盟子推客身份标识（不能传入接口调用者自己的pid）", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "subUnionId", value = "子渠道标识，您可自定义传入字母、数字或下划线，最多支持80个字符，该参数会在订单行查询接口中展示", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "couponUrl", value = "优惠券领取链接，在使用优惠券、商品二合一功能时入参，且materialId须为商品详情页链接", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "chainType", value = "转链类型，默认短链，短链有效期60天1：长链2：短链 3：长链+短链", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "giftCouponKey", value = "礼金批次号", required = false, dataType = "String", paramType = "query")
    })
    @RepeatSubmit
    @GetMapping("/convertLinkJD")
    public AjaxResult convertLinkJD(
            @RequestParam Long unionId,
            @RequestParam String materialId,
            @RequestParam(required = false) Long positionId,
            @RequestParam(required = false) String childPid,
            @RequestParam(required = false) String subUnionId,
            @RequestParam(required = false) String couponUrl,
            @RequestParam(required = false) Integer chainType,
            @RequestParam(required = false) String giftCouponKey,
            HttpServletRequest request, HttpServletResponse response) {
        if (unionId == null || StringUtils.isBlank(materialId)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("unionId", unionId + "");
        paramMap.put("materialId", materialId);
        if (positionId != null) paramMap.put("positionId", positionId + "");
        if (StringUtils.isNotBlank(childPid)) paramMap.put("childPid", childPid);
        if (StringUtils.isNotBlank(subUnionId)) paramMap.put("subUnionId", subUnionId);
        if (StringUtils.isNotBlank(couponUrl)) paramMap.put("couponUrl", couponUrl);
        if (chainType != null) paramMap.put("chainType", chainType + "");
        if (StringUtils.isNotBlank(giftCouponKey)) paramMap.put("giftCouponKey", giftCouponKey);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.CONVERT_LINK_JD_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 拼多多商品转链
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "拼多多商品转链", notes = "该接口针对拼多多商品进行转链，转链后即可进行推广并赚取佣金" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=63")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsSign", value = "商品goodsSign", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "zsDuoId", value = "招商多多客ID", required = false, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/convertLinkPDD")
    public AjaxResult convertLinkPDD(
            @RequestParam String goodsSign,
            @RequestParam(required = false) String zsDuoId,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(goodsSign)) {
            return AjaxResult.error("参数错误");
        }
        LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("pid", ShoppingConstant.PDD_PID);
        JSONObject object = new JSONObject();
        object.put("uid", loginAppUser.getAppUser().getUserId() + "");
        paramMap.put("customParameters", object.toJSONString());//生成签名时使用原json字符串
        paramMap.put("goodsSign", goodsSign);
        if (StringUtils.isNotBlank(zsDuoId)) paramMap.put("zsDuoId", zsDuoId);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));
        paramMap.put("customParameters", URLEncoder.encode(object.toJSONString()));//访问大淘客服务器时进行转码

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.CONVERT_LINK_PDD_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * 官方活动会场转链
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "官方活动会场转链", notes = "此接口将官方活动商品批量转链" +
            "<br>具体返回值可参考：http://www.dataoke.com/kfpt/api-d.html?id=31")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "promotionSceneId", value = "联盟官方活动ID，从联盟官方活动页获取或从大淘客官方活动推广接口获取", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pid", value = "推广pid，默认为在“我的应用”添加的pid", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "relationId", value = "渠道id将会和传入的pid进行验证，验证通过将正常转链，请确认填入的渠道id是正确的", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "unionId", value = "自定义输入串，英文和数字组成，长度不能大于12个字符，区分不同的推广渠道", required = false, dataType = "String", paramType = "query"),
    })
    @RepeatSubmit
    @GetMapping("/convertLinkActivity")
    public AjaxResult convertLinkActivity(
            @RequestParam String promotionSceneId,
            @RequestParam(required = false) String pid,
            @RequestParam(required = false) String relationId,
            @RequestParam(required = false) String unionId,
            HttpServletRequest request, HttpServletResponse response) {
        if (StringUtils.isBlank(promotionSceneId)) {
            return AjaxResult.error("参数错误");
        }
        final String version = "v1.0.0";//接口版本号
        TreeMap<String, String> paramMap = new TreeMap<>();
        paramMap.put("appKey", ShoppingConstant.APP_KEY);
        paramMap.put("version", version);

        paramMap.put("goodsSign", promotionSceneId);
        if (StringUtils.isNotBlank(pid)) paramMap.put("pid", pid);
        if (StringUtils.isNotBlank(relationId)) paramMap.put("relationId", relationId);
        if (StringUtils.isNotBlank(unionId)) paramMap.put("unionId", unionId);

        paramMap.put("sign", SignMD5Util.getSignStr(paramMap, ShoppingConstant.APP_SECRET));

        String reslutStr = HttpUtils.sendGet(ShoppingConstant.CONVERT_LINK_ACTIVITY_URL, paramMap);
        return convertDataokeData(reslutStr);
    }

    /**
     * @throws
     * @title 转换大淘客获取数据结果
     * @description
     * @author admin
     * @updateTime 2021/3/15 10:42
     */
    private AjaxResult convertDataokeData(String resultStr) {
        if (StringUtils.isBlank(resultStr) || resultStr.indexOf("{") == -1 || resultStr.indexOf("}") == -1) {
            return AjaxResult.error(resultStr);
        }
        JSONObject object = JSONObject.parseObject(resultStr);
        Integer code = object.getInteger("code");
        if (code.intValue() == 0) {
            if (object.get("data") instanceof JSONObject) {
                return AjaxResult.success(object.getJSONObject("data"));
            }
            if (object.get("data") instanceof JSONArray) {
                return AjaxResult.success(object.getJSONArray("data"));
            }
            return AjaxResult.success(object.get("data"));
        }
        logger.error("<ShoppingController." + Thread.currentThread().getStackTrace()[2].getMethodName() + ">获取大淘客数据失败，" + resultStr);
        return AjaxResult.error(object.getString("msg"));
    }

    /**
     * @throws
     * @title 转换大淘客获取数据结果
     * @description
     * @author admin
     * @updateTime 2021/3/15 10:42
     */
    private AjaxResult convertDataokeData(String resultStr, AppBrowseRecord appBrowseRecord) {
        if (StringUtils.isBlank(resultStr) || resultStr.indexOf("{") == -1 || resultStr.indexOf("}") == -1) {
            return AjaxResult.error(resultStr);
        }
        JSONObject object = JSONObject.parseObject(resultStr);
        Integer code = object.getInteger("code");
        if (code.intValue() == 0) {
            if (object.get("data") instanceof JSONObject) {
                if (appBrowseRecord != null)
                    appBrowseRecord.setGoodsInfo(object.getJSONObject("data").toJSONString());
                return AjaxResult.success(object.getJSONObject("data"));
            } else if (object.get("data") instanceof JSONArray) {
                JSONArray array = object.getJSONArray("data");
                if (appBrowseRecord != null)
                    appBrowseRecord.setGoodsInfo(array.size() > 0 ? array.getJSONObject(0).toJSONString() : "");
                return AjaxResult.success(array);
            }
            return AjaxResult.success(object.get("data"));
        }
        logger.error("<ShoppingController." + Thread.currentThread().getStackTrace()[2].getMethodName() + ">获取大淘客数据失败，" + resultStr);
        return AjaxResult.error(object.getString("msg"));
    }

    private static PopClient client = new PopHttpClient(ShoppingConstant.PDD_CLIENT_ID, ShoppingConstant.PDD_CLIENT_SECRET);

    /**
     * 查询用户是否备案过（拼多多）
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "查询用户是否备案过（拼多多）")
    @RepeatSubmit
    @GetMapping("/queryKeeponRecordPDD")
    public AjaxResult queryKeeponRecordPDD(
            HttpServletRequest request, HttpServletResponse response) {
        try {

            LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);

            int result = queryKeeponRecordPDD(loginAppUser.getAppUser().getUserId());
            if (result == -1) {
                return AjaxResult.error("拼多多官方接口已修改，请联系管理员");
            }
            return AjaxResult.success(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error();
    }

    /**
     * 生成用户备案链接（拼多多）
     */
    @PreAuthorize("@ss.hasPermi('app:shopping:all')")
    @ApiOperation(value = "生成用户备案链接（拼多多）")
    @RepeatSubmit
    @GetMapping("/generatePDD")
    public AjaxResult generatePDD(
            HttpServletRequest request, HttpServletResponse response) {
        try {

            LoginAppUser loginAppUser = tokenService.getLoginAppUser(request);

            int resultInt = queryKeeponRecordPDD(loginAppUser.getAppUser().getUserId());
            if (resultInt == 1) {
                return AjaxResult.error("该用户已经备案过了");
            } else if (resultInt == 0) {
                //未备案过
                JSONObject object = new JSONObject();
                object.put("uid", loginAppUser.getAppUser().getUserId() + "");

                PddDdkRpPromUrlGenerateRequest requestPDD = new PddDdkRpPromUrlGenerateRequest();
                requestPDD.setChannelType(10);
                requestPDD.setGenerateWeApp(true);
                List<String> pidList = new ArrayList<>();
                pidList.add(ShoppingConstant.PDD_PID);
                requestPDD.setPIdList(pidList);
                requestPDD.setCustomParameters(object.toJSONString());

                PddDdkRpPromUrlGenerateResponse responsePDD = client.syncInvoke(requestPDD);
                JSONObject result = JSONObject.parseObject(JsonUtil.transferToJson(responsePDD));
                if (result != null && result.getJSONObject("rp_promotion_url_generate_response") != null) {
                    return AjaxResult.success("生成备案链接成功", result.getJSONObject("rp_promotion_url_generate_response").getJSONArray("url_list").getJSONObject(0).getString("mobile_url"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error();
    }

    /**
     * @title 查询用户是否在拼多多备案过
     */
    private int queryKeeponRecordPDD(Long userId) throws Exception {
        JSONObject object = new JSONObject();
        object.put("uid", userId.toString());

        PddDdkMemberAuthorityQueryRequest request = new PddDdkMemberAuthorityQueryRequest();
        request.setPid(ShoppingConstant.PDD_PID);
        request.setCustomParameters(object.toJSONString());
        PddDdkMemberAuthorityQueryResponse response = client.syncInvoke(request);
        JSONObject result = JSONObject.parseObject(JsonUtil.transferToJson(response));
        if (result != null && result.getJSONObject("authority_query_response") != null) {
            return result.getJSONObject("authority_query_response").getIntValue("bind");
        }
        return -1;
    }

}
